﻿using B.S.Medical.Api.Read.Application.Command.Department;
using B.S.Medical.Domain.Department;
using B.S.Medical.ErrorCode;
using B.S.Medical.Infrastructure.Interface;
using MediatR;

namespace B.S.Medical.Api.Read.Application.Handler.Department
{
    public class LogCommandHandle : IRequestHandler<LogCommand, ApiPageing<LogModel>>
    {
        private readonly IBaseRepository<LogModel> _logRepository;

        public LogCommandHandle(IBaseRepository<LogModel> logRepository)
        {
            _logRepository = logRepository;
        }

        public Task<ApiPageing<LogModel>> Handle(LogCommand request, CancellationToken cancellationToken)
        {
            ApiPageing<LogModel> res = new ApiPageing<LogModel>();
            var model= _logRepository.GetAll().Where(x => x.IsDeleted == false);
            res.TotaCount=model.Count();
            res.Msg="数据显示成功";
            res.PageData=model.OrderByDescending(x=>x.Id).Skip((request.Index-1)*request.Size).Take(request.Size).ToList();
            res.Code=ApiEnum.Success;
            return Task.FromResult(res);
        }
    }
}
